<?php
App::Import('Controller','Invites.BaseInvites');
class InvitesController extends BaseInvitesController
{

	function _isAdmin()
	{
		return $this->Session->check('Auth.Account');
	}

	function inviteFriends($listing_id = null)
	{		
		$this->Listing = cri('Listing');
		$this->Listing->recursive = -1;
		$listingData = $this->Listing->findById($listing_id);
		if(empty($listingData))
		{
			$this->errorMsg(__('Invalid URL'));
			$this->redirect($this->referer());
		}
		if(!empty($this->data))
		{
			$senderName = $this->data['Sender']['name'];
			$senderEmail = $this->data['Sender']['email'];
			$this->set('sender_name',$senderName);
			$this->__setEmailParams();
		}	
		
		$siteUrl = Configure::read('cmsConfig.Backend.siteUrl');
		$listingUrl= $siteUrl.'/listings/view/'.$listingData['Listing']['slug'];
		$listing_title = $listingData['Listing']['title'];
		
		$this->set(compact('listingUrl','listingLink','listing_title'));
		$this->set('listing_id',$listing_id);
		$this->set('listing_title',$listing_title);
		$this->set('siteName',Configure::read('cmsConfig.Backend.siteName'));
		$this->pageTitle = sprintf(__('Email %s Listing to your friends'),$listingData['Listing']['title']);
		parent::inviteFriends();
	}

	function __setEmailParams()
	{
		parent::__setEmailParams();
		$this->Email->setFrom($this->data['Sender']['email'],$this->data['Sender']['name']);
		$this->Email->template = 'share_listing_with_friend';
		$this->Email->subject = __('Share Listing');
		$this->Email->sendAs = 'both';		
	}

}?>